#ifndef _FRAMEWORK_DBCPARSE_H_
#define _FRAMEWORK_DBCPARSE_H_

#include "zdbc.h"

#include <QString>
#include <unordered_map>
#include <map>

using CanId = uint32_t;

class DbcParser
{
public:
    DbcParser();
    ~DbcParser();

    bool load(const QString& path);
    void printMessages();
    bool updateDbcMsg(const CanId& msgId, const std::string& sigName, double sigValue);
    bool encodeAsCanMessage(DBCMessage* msg, std::vector<uint8_t>& output);
    bool encodeAsCanFdMessage(DBCMessage* msg, std::vector<uint8_t>& output);
    void foreachDbcMessageMap(std::function<void(DBCMessage* msg)> cb);
    bool encodeCanMsg(DBCMessage* msg, void* obj);
    int  getMsgIdBySigName(const char* sigName);

    static void printMsg(const DBCMessage* dbcMsg);
    static bool isEmptySiganl(const DBCSignal& sig);
    static void buildDbcMsg(DBCMessage& dbcMsg, const std::string& sigName, const std::string& sigValue);
    static DBCSignal* findSignalWithMessage(DBCMessage& dbcMsg, const std::string& sigName);

private:
    void ReadAllMessage();

    QString                               itsFilePath;
    std::unordered_map<CanId, DBCMessage> itsMessages;
    DBCHandle                             itsDbcHandler;
    std::map<std::string, int>            itsMsgMap;

};


#endif
